package jdbc;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.xml.ws.Response;

import entity.User;

public class UsrDao {
	static DBUtil DB = null;
	static Connection con = DB.getconnection();
	static PreparedStatement ps=null;
	static ResultSet rs=null;
	public static boolean JudgeUsr(User u){
		boolean ifUser=false;
		
		String sql="select * from test where usrname=? and usrpassword=?";
		try {
			ps=con.prepareStatement(sql);
			ps.setString(1, u.getName());
			ps.setString(2, u.getPassword());
			rs=ps.executeQuery();
			if (rs.next()==true){
				ifUser=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ifUser;
	}
	public static String ShowInfo(User u){
		String info=null;
		String sql="select * from test where usrname=? and usrpassword=?";
		try {
			
			ps.setString(1, u.getName());
			ps.setString(2, u.getPassword());
			rs=ps.executeQuery();
			while (rs.next()){
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return info;
		
	}
	public static void ReginUsr(User u){
		System.out.println(u.getName()+u.getPassword());
		String sql ="insert into test(usrname,usrpassword) values(?,?)";
		try {
			ps=con.prepareStatement(sql);
			ps.setString(1, u.getName());
			ps.setString(2, u.getPassword());
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
